{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "%load_ext autoreload\n",
    "%autoreload 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import math\n",
    "import random\n",
    "import time\n",
    "\n",
    "from collections import defaultdict\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from tf_rl.simulation import DoublePendulum\n",
    "from tf_rl import simulate"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "DOUBLE_PENDULUM_PARAMS = {\n",
    "    'g_ms2': 9.8, # acceleration due to gravity, in m/s^2\n",
    "    'l1_m': 1.0, # length of pendulum 1 in m\n",
    "    'l2_m': 2.0, # length of pendulum 2 in m\n",
    "    'm1_kg': 1.0, # mass of pendulum 1 in kg\n",
    "    'm2_kg': 1.0, # mass of pendulum 2 in kg\n",
    "    'damping': 0.4,\n",
    "    'max_control_input': 20.0\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "d = DoublePendulum(DOUBLE_PENDULUM_PARAMS)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "d.perform_action(0.2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<?xml version=\"1.0\"?>\n",
       "\n",
       "<svg height=\"340\" width=\"420\" >\n",
       "\n",
       " <g style=\"fill-opacity:1.0; stroke:black;\n",
       "\n",
       "  stroke-width:1;\">\n",
       "\n",
       "  <rect x=\"10\" y=\"10\" height=\"300\"\n",
       "\n",
       "        width=\"400\" style=\"fill:none;\" />\n",
       "\n",
       "  <line x1=\"200\" y1=\"150\" x2=\"212\" y2=\"187\" />\n",
       "\n",
       "  <line x1=\"212\" y1=\"187\" x2=\"278\" y2=\"233\" />\n",
       "\n",
       "  <circle cx=\"200\" cy=\"150\" r=\"5\"\n",
       "\n",
       "          style=\"fill:red;\" />\n",
       "\n",
       "  <circle cx=\"212\" cy=\"187\" r=\"3\"\n",
       "\n",
       "          style=\"fill:blue;\" />\n",
       "\n",
       "  <circle cx=\"278\" cy=\"233\" r=\"3\"\n",
       "\n",
       "          style=\"fill:green;\" />\n",
       "\n",
       "  <text x=\"10\" y=\"335\" font-size=\"15\">\n",
       "\n",
       "   Reward = -2.1\n",
       "\n",
       "  </text>\n",
       "\n",
       " </g>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<tf_rl.utils.svg.Scene instance at 0x7f7ab8f37290>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Interrupted\n"
     ]
    }
   ],
   "source": [
    "try:\n",
    "    simulate(d, fps=30, actions_per_simulation_second=1, speed=1.0, simulation_resultion=0.01)\n",
    "except KeyboardInterrupt:\n",
    "    print(\"Interrupted\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
